package com.smartcommunity.api.engine;

import com.smartcommunity.api.engine.fallBack.EngineApiFallBack;
import com.smartcommunity.bean.model.Result;
import com.smartcommunity.entity.people.People;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 结构化引擎服务接口
 *
 * <p>
 * <pre class="code">
 * EngineApi engineApi = applicationContext.getBean(EngineApi.class);
 * Map<String, Object> person = new HashMap<>();
 * person.put("id", "1");
 * person.put("pic", "url");
 * person.put("idCard", "idCard");
 * person.put("name", "leon");
 * Result result = engineApi.uploadPerson(person);
 * </pre>
 *
 * @author 渔七
 * @since 2023年1月3日
 */
@FeignClient(value = "np-zhsq-engine-service", fallback = EngineApiFallBack.class)
public interface EngineApi {

    /**
     * 上传一个常口人员
     */
    @RequestMapping(method = RequestMethod.POST, value = "/person/uploadPerson", consumes = MediaType.APPLICATION_JSON_VALUE)
    Result uploadPerson(@RequestBody Map<String, Object> person);

    @RequestMapping(method = RequestMethod.POST, value = "/person/uploadPersons", consumes = MediaType.APPLICATION_JSON_VALUE)
    Result uploadPersons(@RequestBody List<Map<String, Object>> persons);

    /**
     * 删除一个常口人员
     *
     * @param personId {@link People#getFeatureId()}
     */
    @RequestMapping(method = RequestMethod.GET, value = "/person/deletePerson", consumes = MediaType.APPLICATION_JSON_VALUE)
    Result deletePerson(@RequestParam(name = "personId") Long personId);

    /**
     * 删除一个常口人员
     *
     * @param personIds {@link People#getFeatureId()}
     */
    @RequestMapping(method = RequestMethod.POST, value = "/person/deletePersons", consumes = MediaType.APPLICATION_JSON_VALUE)
    Result deletePersons(@RequestBody List<Long> personIds);

    /**
     * 通过vid查询人员信息
     *
     * @param vids vid列表
     */
    @RequestMapping(method = RequestMethod.GET, value = "/person/getVidPersons", consumes = MediaType.APPLICATION_JSON_VALUE)
    Result getPersonByVids(@RequestParam(name = "vids") Long... vids);

    /**
     * 通过身份证列表查询人员信息
     *
     * @param idcards 身份证列表
     */
    @RequestMapping(method = RequestMethod.GET, value = "/person/getVidPersonsByIdCard", consumes = MediaType.APPLICATION_JSON_VALUE)
    Result getVidPersonsByIdCard(@RequestParam(name = "idcards") String... idcards);

    @RequestMapping(method = RequestMethod.GET, value = "/person/hello", consumes = MediaType.APPLICATION_JSON_VALUE)
    String hello();

    /**
     * 置信数据绑定
     */
    @RequestMapping(method = RequestMethod.POST, value = "/person/binds", consumes = MediaType.APPLICATION_JSON_VALUE)
    Result binds(List<Map<String, Object>> infos);

    /**
     * 置信数据解绑
     */
    @RequestMapping(method = RequestMethod.POST, value = "/person/unbinds", consumes = MediaType.APPLICATION_JSON_VALUE)
    Result unbinds(List<Map<String, Object>> infos);

    /**
     * 人脸通行记录-根据条件查询fse的通行记录
     *
     * @param fseSearchConditionObj 查询条件
     */
    @RequestMapping(method = RequestMethod.POST, value = "/faceFeature/queryFeatures", consumes = MediaType.APPLICATION_JSON_VALUE)
    Result<List<Map<String, Object>>> queryFaceRecords(@RequestBody Map<String, Object> fseSearchConditionObj);

    /**
     * 根据图片检索常口
     */
    @RequestMapping(method = RequestMethod.POST, path = "/person/getPersonsByImage", consumes = MediaType.APPLICATION_JSON_VALUE)
    Result<List<Map<String, Object>>> getPersonsByImage(@RequestBody Map<String, Object> param);

    /**
     * 根据图片url查询vid
     */
    @RequestMapping(method = RequestMethod.POST, path = "/features/searchVidsByUrl", consumes = MediaType.APPLICATION_JSON_VALUE)
    Result<Map<String, Object>> searchVidsByUrl(@RequestBody Map<String, Object> param);

    /**
     * 通过featureId或者vid常口库中存储的特征
     */
    @RequestMapping(method = RequestMethod.GET, path = "/person/getFeatureByFeatureId")
    Result<String> getFeatureByFeatureId(@RequestParam(name = "fid") String fid);

    /**
     * 添加人脸信息
     * @param condition
     * @return
     */
    @RequestMapping(path = "/compreFace/subjects", method = RequestMethod.POST)
    Result<Object> addSubject(@RequestBody @Validated Map<String, Object> condition);

    @RequestMapping(path = "/compreFace/subjects/{subjectName}", method = RequestMethod.DELETE)
    Result<Object> deleteSubject(@PathVariable(value = "subjectName") String subjectName);

    @RequestMapping(path = "/compreFace/facesBse64", method = RequestMethod.POST)
    Result<Object> addFacesByBase64(@RequestParam(name = "subject") String subject,@RequestBody Map<String, Object> base64);
}
